package com.atguigu.demojuc.chap02;

import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockDemo2 {

    //private final ReentrantLock lock = new ReentrantLock(); // 非公平锁   具备可重入性的排他锁    sync = new NonfairSync();
    private final ReentrantLock lock = new ReentrantLock(true); //公平锁   sync = fair ? new FairSync() : new NonfairSync();
    public void a(){
        lock.lock();
        this.b();
        System.out.println("a");
        lock.unlock();
    }

    public void b(){
        lock.lock();
        System.out.println("b");
        lock.unlock();
    }

    public static void main(String[] args) {
        new ReentrantLockDemo2().a();
    }
}